
function upload() {
    var obj = document.getElementById("image");
    obj.click();
    obj.addEventListener(
        "change",function () {
            var file = obj.files[0];
            var formData = new FormData();
            var token = document.getElementsByName("csrfmiddlewaretoken")[0].value;
            formData.append("csrfmiddlewaretoken",token);
            formData.append("file",file);
            $.ajax({
                url:"/upload/",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                success: function (data) {
                    location.reload();
                    alert(data["state"]);
                },
                error: function (error) {
                    console.log(error)
                }
            })
        }
    )

}

function down() {
    var values = [];
    var checked = $("input[type='checkbox']:checked").each(
        function () {
            values.push($(this).val())
        }
    );
    $.ajax({
       url: "/download/",
       type: "get",
       data: {"file": values},
       traditional: true,
       success: function (data) {
           alert(data["state"]);
           $("input[type='checkbox']").attr("checked",false)
       },
       error: function (error) {
           console.log(error)
       }
    });
}